import { BasicColumn, FormSchema } from '/@/components/Table';
import { rules } from '/@/utils/helper/validator';
import {listAllPayWay} from "../payWay/payWay.api";
import { render } from '/@/utils/common/renderUtils';
import { DescItem } from '/@/components/Description/index';

const isCustomPage = (type) => type === "2"

export const columns: BasicColumn[] = [
  {
    title: '接口名称',
    width: 100,
    dataIndex: 'ifName'
  },
  {
    title: '接口代码',
    width: 100,
    dataIndex: 'ifCode',
  },
  {
    title: '状态',
    width: 60,
    dataIndex: 'status',
    customRender: ({text}) => {
      let color = "green"
      if (text == '0') color = 'red'
      if (text == '1') color = 'green'
      
      return render.renderTag(render.renderDict(text, 'data_use_status'), color)
    }
  },
  {
    title: '创建时间',
    width: 150,
    dataIndex: 'createdAt',
  }
];

export const searchFormSchema: FormSchema[] = [
  {
    field: 'ifCode',
    label: '接口代码',
    component: 'Input',
    // colProps: {span: 12},
  },
  {
    field: 'ifName',
    label: '接口名称',
    component: 'Input',
    // colProps: {span: 12},
  },
  {
    label: '状态',
    field: 'status',
    component: 'JDictSelectTag',
    componentProps: {
      dictCode:'data_use_status',
      placeholder:'请选择支付接口状态'
    },
    // colProps: {span: 6},
  }
];

export const formDetailSchema : DescItem[] = [
  {
    field: 'ifCode',
    label: '接口代码'
  },
  {
    field: 'ifName',
    label: '接口名称'
  },
  {
    field: 'isMchMode',
    label: '普通商户模式',
    render: (curVal, data) => {
      let color = "green"
      if (curVal == '0') color = '#FFCC33'
      if (curVal == '1') color = 'green'
      
      return render.renderTag(render.renderDict(curVal, 'support_status'), color)
    },
  },
  {
    field: 'isIsvMode',
    label: '服务商模式',
    render: (curVal, data) => {
      let color = "green"
      if (curVal == '0') color = '#FFCC33'
      if (curVal == '1') color = 'green'
      
      return render.renderTag(render.renderDict(curVal, 'support_status'), color)
    },
  },
  {
    field: 'configPageType',
    label: '支付参数配置页面类型',
    render: (curVal, data) => {
      let color = "green"
      if (curVal == '0') color = '#FFCC33'
      if (curVal == '1') color = 'green'
      
      return render.renderTag(render.renderDict(curVal, 'pay_config_page_type'), color)
    },
  },
  {
    field: 'isvParams',
    label: '服务商接口配置',
    labelMinWidth: 120
  },
  {
    field: 'isvsubMchParams',
    label: '特约商户接口配置',
    labelMinWidth: 120
  },
  {
    field: 'normalMchParams',
    label: '普通商户接口配置',
    labelMinWidth: 120
  },

  {
    field: 'status',
    label: '状态',
    render: (curVal, data) => {
      let color = "green"
      if (curVal == '0') color = 'red'
      if (curVal == '1') color = 'green'
      
      return render.renderTag(render.renderDict(curVal, 'data_use_status'), color)
    },
  },

  {
    field: 'wayCodes', 
    label: '支持的支付方式',
    render: (curVal, data) => {
      let color = "green"
      if (curVal == '0') color = 'red'
      if (curVal == '1') color = 'green'
      
      return render.renderTag(curVal, color)
    },
  },
  {
    field: 'createdAt',
    label: '创建时间'
  },
  {
    field: 'remark',
    label: '备注',
    labelMinWidth: 60
  }
  
];

export const formSchema: FormSchema[] = [
  {
    label: 'id',
    field: 'id',
    component: 'Input',
    show: false
  },
  {
    field: 'ifCode',
    label: '接口代码',
    required: true,
    component: 'Input',
    colProps: {span: 12},
    dynamicDisabled: ({values}) => {
      return !!values.id;
    },
  },
  {
    field: 'ifName',
    label: '接口名称',
    required: true,
    component: 'Input',
    colProps: {span: 12}
  },
  {
    field: 'isMchMode',
    label: '普通商户模式',
    required: true,
    component: 'JDictSelectTag',
    componentProps: {
      dictCode:'support_status',
      type: "radio"
    },
    
    colProps: {span: 12},
  },
  {
    field: 'isIsvMode',
    label: '服务商模式',
    required: true,
    component: 'JDictSelectTag',
    componentProps: {
      type: "radio",
      dictCode:'support_status'
    },
    colProps: {span: 12},
  },
  {
    field: 'configPageType',
    label: '支付参数配置页面类型',
    required: true,
    labelWidth: 150,
    component: 'JDictSelectTag',
    componentProps: {
      type: "radio",
      dictCode:'pay_config_page_type',
      placeholder: '请选择页面类型'
    },
    colProps: {span: 12},
  },
  {
    field: 'isvParams',
    labelWidth: 150,
    label: '服务商接口配置定义描述',
    slot: 'isvParams',
    component: 'InputTextArea',
    colProps: {span: 24},
    ifShow: ({ values }) => {
      return values.isIsvMode ? values.isIsvMode == '1' : true && !isCustomPage(values.configPageType);
    },
  },
  {
    field: 'isvsubMchParams',
    labelWidth: 160,
    label: '特约商户接口配置定义描述',
    component: 'InputTextArea',
    slot: 'isvsubMchParams',
    colProps: {span: 24},
    ifShow: ({ values }) => {
      return (values.isIsvMode ? values.isIsvMode == '1' : true) && !isCustomPage(values.configPageType);
    },
  },
  {
    field: 'normalMchParams',
    labelWidth: 160,
    label: '普通商户接口配置定义描述',
    component: 'InputTextArea',
    slot: 'normalMchParams',
    colProps: {span: 24},
    ifShow: ({ values }) => {
      return values.isMchMode ? values.isMchMode == '1' : true && !isCustomPage(values.configPageType);
    },
  },
  {
    field: 'status',
    label: '状态',
    component: 'JDictSelectTag',
    defaultValue: "1",
    componentProps: {
      dictCode:'data_use_status',
      type: "radio"
    },
  },
  {
    field: 'remark',
    label: '备注',
    component: 'InputTextArea',
  },
  {
    label: '支持的支付方式',
    field: 'wayCodes',
    component: 'ApiSelect',
    colProps: {span: 24},
    componentProps: {
      mode: "multiple",
      api: listAllPayWay,
      labelField: 'wayName',
      valueField: 'wayCode',
    },
  },
]
